﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct BinNode
{
	char ch;
	struct BinNode* lChild;
	struct BinNode* rChild;
};
//1.二叉树的递归遍历；
void recurseTraverse(struct BinNode* root)
{
	if (NULL == root)
	{
		return;
	}

	//5.先序遍历，先访问根节点；根->左->右
	//printf("2.输出二叉树的节点：%c\n", root->ch);

	//3.递归遍历左子树；
	recurseTraverse(root->lChild);
	//6.中序遍历，先访问左子树节点；左->根->右
	//printf("2.输出二叉树的节点：%c\n", root->ch);
	//4.递归遍历右子树；
	recurseTraverse(root->rChild);
	//7.后序遍历，先访问左子树节点，再是右节点，最后是根节点；左->右->根
	printf("2.输出二叉树的节点：%c\n", root->ch);
}
void testBinaryTree()
{
	struct BinNode nodeA = { 'A',NULL,NULL };
	struct BinNode nodeB = { 'B',NULL,NULL };
	struct BinNode nodeC = { 'C',NULL,NULL };
	struct BinNode nodeD = { 'D',NULL,NULL };
	struct BinNode nodeE = { 'E',NULL,NULL };
	struct BinNode nodeF = { 'F',NULL,NULL };
	struct BinNode nodeG = { 'G',NULL,NULL };
	struct BinNode nodeH = { 'H',NULL,NULL };

	nodeA.lChild = &nodeB;
	nodeA.rChild = &nodeF;

	nodeB.rChild = &nodeC;
	nodeC.lChild = &nodeD;
	nodeC.rChild = &nodeE;

	nodeF.rChild = &nodeG;
	nodeG.lChild = &nodeH;

	recurseTraverse(&nodeA);//A,B,C,D,E,F,G,H --> B,D,C,E,A,F,H,G --> D,E,C,B,H,G,F,A
}

//main228：二叉树递归遍历
int main228()
{
	testBinaryTree();

	system("pause");
	return EXIT_SUCCESS;
}